﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using sharp_net.Repositories;
using sharp_net.Repositories.MongoDB;
using MongoDB.Bson;

namespace danreng.Domain {
    public class Item: DomainMongo, IAggregateRoot {

        [Required]
        public ObjectId UserId { get; set; }
        [Required]
        public ObjectId LibraryId { get; set; }

        [Required]
        [MaxLength(200)]
        public string Title { get; set; }
        public string ContentRich { get; set; }

        public decimal DemandPrice { get; set; }

        public int GrabRateBysec { get; set; }

        public int Grade { get; set; }

        public string RemarkRich { get; set; }

        public void Update(ItemData data) {
            base.Update((DomainMongoData)data);
            if (!string.IsNullOrEmpty(data.LibraryId))
                this.LibraryId = ObjectId.Parse(data.LibraryId);
            if (!string.IsNullOrEmpty(data.Title))
                this.Title = data.Title;
            if (!string.IsNullOrEmpty(data.ContentRich))
                this.ContentRich = data.ContentRich;
            if (data.DemandPrice != 0)
                this.DemandPrice = data.DemandPrice;
            if (data.Grade != 0)
                this.Grade = data.Grade;
            if (!string.IsNullOrEmpty(data.RemarkRich))
                this.RemarkRich = data.RemarkRich;
        }
    }

    public class ItemData : DomainMongoData {
        public string UserId { get; set; }
        public string LibraryId { get; set; }
        public string Title { get; set; }
        public string ContentRich { get; set; }
        public decimal DemandPrice { get; set; }
        public int GrabRateBysec { get; set; }
        public int Grade { get; set; }
        public string RemarkRich { get; set; }
    }
}
